package com.jic.veteran.portal.controller;

import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.Maps;
import com.jic.veteran.common.api.CommonPage;
import com.jic.veteran.common.api.CommonResult;
import com.jic.veteran.model.InvoiceDetail;
import com.jic.veteran.model.InvoiceInfo;
import com.jic.veteran.model.ProjectDonationDetail;
import com.jic.veteran.portal.service.InvoiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


@Api(tags = "InvoiceController")
@Controller
@RequestMapping("/invoice")
public class InvoiceController {

    @Autowired
    private InvoiceService invoiceService;
//
//    @ApiOperation("发票抬头新增")
//    @RequestMapping(value = "/info/add", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult addInvoiceInfo(@RequestBody InvoiceInfo invoiceInfo) {
//        int count = invoiceService.addInvoiceInfo(invoiceInfo);
//        if(count>0) {
//            return CommonResult.success(count);
//        }
//        return CommonResult.success("发票抬头已存在或添加发票抬头遇到问题");
//    }
//
//    @ApiOperation("发票抬头获取")
//    @RequestMapping(value = "/info/get/{openid}", method = RequestMethod.GET)
//    @ResponseBody
//    public CommonResult getInvoiceInfo(@PathVariable(value = "openid") String openid,
//                                       @RequestParam(value = "invoiceType", required = false) String invoiceType) {
//        List<InvoiceInfo> invoiceInfo = invoiceService.getInvoiceInfo(openid, invoiceType);
//        Map<String, List<InvoiceInfo>> invoiceInfoMap = Maps.newHashMapWithExpectedSize(3);
//        invoiceInfoMap.put("invoiceInfo", invoiceInfo);
//        return CommonResult.success(invoiceInfoMap);
//    }
//
//    @ApiOperation("开票历史查询")
//    @RequestMapping(value = "/detail/list/{openid}", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult<CommonPage<InvoiceDetail>> historyList(@PathVariable(value = "openid") String openid,
//                                                @RequestParam(value = "pageSize", defaultValue = "50") Integer pageSize,
//                                                @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
//        List<InvoiceDetail> invoiceDetailList = invoiceService.historyList(openid, pageSize, pageNum);
//
//        return CommonResult.success(CommonPage.restPage(invoiceDetailList));
//    }
//
//    @ApiOperation("未开票列表查询")
//    @RequestMapping(value = "/detail/unInvoice/{openid}", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult<List<ProjectDonationDetail>> unInvoiceList(@PathVariable(value = "openid") String openid) {
//        List<ProjectDonationDetail> invoiceDetailList = invoiceService.unInvoiceList(openid);
//
//        return CommonResult.success(invoiceDetailList);
//    }
//
//    @ApiOperation("发票申请")
//    @RequestMapping(value = "/detail/add/{openid}/{invoiceType}", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult addInvoiceDetail(@PathVariable(value = "openid") String openid,
//                                         @PathVariable("invoiceType") String invoiceType,
//                                         @RequestBody List<String> ids) {
//        List<InvoiceInfo> invoiceInfo = invoiceService.getInvoiceInfo(openid, invoiceType);
//        if(ObjectUtil.isEmpty(invoiceInfo)) {
//            return CommonResult.failed("请先维护发票抬头");
//        }
//        int count = invoiceService.batchAddInvoiceDetail(ids,"",openid, invoiceType);
//        if(count>0) {
//            return CommonResult.success(count);
//        }
//        return CommonResult.failed("提交失败");
//    }
//    @ApiOperation("获取开票信息")
//    @RequestMapping(value = "/detail/info/{orderId}", method = RequestMethod.GET)
//    @ResponseBody
//    public CommonResult info(@PathVariable String orderId) {
//        InvoiceDetail invoiceDetail = invoiceService.getItem(orderId);
//        return CommonResult.success(invoiceDetail);
//    }
}
